package com.koron.css2.newProjectCenter.print;

import com.koron.css2.ServerInterface;
import com.koron.css2.newProjectCenter.bean.query.PjPrintQuery;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import com.koron.util.PrintInterfaceImpl;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class NonResidentSecondaryWaterSupplyContract implements ServerInterface {

    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            PjPrintQuery pjPrintQuery = JsonUtils.objectToPojo(req.getData(), PjPrintQuery.class);
            // 1. 获取打印数据
            ArrayList<HashMap<String, String>> result = NonResidentWaterSupplyContract.getPrintDate(factory, pjPrintQuery);
            // 2. 生成打印id
            String key = PrintInterfaceImpl.setPrintData(result);
            List<String> keys = new ArrayList<String>();
            keys.add(key);
            // 3. 返回打印id
            MessageBean<List> messageBean = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "非居民二次供水合同获取打印数据成功", List.class);
            messageBean.setData(keys);
            return messageBean;
        } catch (Exception e) {
            logger.error("非居民二次供水合同获取打印数据失败", e);
            return MessageBean.create(Constant.MESSAGE_INT_FAIL, "非居民二次供水合同获取打印数据失败", null);
        }
    }
}
